var validate = {}


validate.isPhone = function( str_phone ){

    let reg = /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/;
    if(!reg.test(str_phone)){
        return false;
    }else{
        return true
    }
}

validate.isMobile = function (str_mobile) {

    var reg = /^1(3|4|5|7|8)\d{9}$/;
    return reg.test(str_mobile );
    
}


validate.isEmpty = function(str_content){

    var str = str_content.replace(/^\s*|\s*$/g,"");
    if(str=='' || str.length<=0){
        return false;
    }else{
        return true;
    }

}

validate.isEmail = function (str_email) {
    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; 
    return myreg.test( str_email );
}

validate.isJson = function(str) {
    if (typeof str == 'string') {
        try {
            JSON.parse(str);
            return true;
        } catch(e) {
            console.log(e);
            return false;
        }
    }
    console.log('It is not a string!')    
}

/**
 * 验证密码是否单一
 * @param {*} str 
 */
validate.isSimple = function (str) {

    var reg=/^(?![^a-zA-Z]+$)(?!\D+$).{6,15}$/;
    return reg.test( str);
}

module.exports = validate